<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
    if (session.getAttribute("loggedIn") != null) 
    {
        if (((Boolean) session.getAttribute("loggedIn"))) 
        {
            if (session.getAttribute("role").equals("courier")) 
            {
                response.sendRedirect("courier_shipments.jsp");
            } 
            else if (!session.getAttribute("role").equals("admin")) 
            {
                response.sendRedirect("index.jsp");
            }
        } else {
            response.sendRedirect("index.jsp");
        }
    } else {
        response.sendRedirect("index.jsp");
    }
%>


<s:layout-render name="/managerlayout.jsp">
    <s:layout-component name="body">
        <s:useActionBean var="actionBean" beanclass="cz.muni.fi.pa165.web.ManagerCustomerActionBean" />
        <h2 style="text-align: center;" class="listHeadline"><f:message key="ManagerCustomerHeadline"/></h2>
        <s:link style="margin: 1%; float:right;" href="/newCustomer.jsp" class="btn btn-mini btn-primary"><f:message key="ManagerCustomerNew"/></s:link>
            <table class="table table-hover">
                <tr>
                    <th><f:message key="Manager-Shipment-list-id"/></th>
                    <th><f:message key="Manager-Customer-list-firstName"/></th>
                    <th><f:message key="Manager-Customer-list-lastName"/></th>
                    <th><f:message key="Manager-Customer-list-city"/></th>
                    <th><f:message key="Manager-Customer-list-street"/></th>
                    <th><f:message key="Manager-Customer-list-streetNumber"/></th>
                    <th><f:message key="Manager-Customer-list-postalCode"/></th>
                    <th><f:message key="Manager-Customer-list-phoneNumber"/></th>
                    <th><f:message key="Manager-Customer-list-email"/></th>
                    <th><f:message key="Manager-Customer-list-edit"/></th>
                    <th><f:message key="Manager-Customer-list-delete"/></th>
                </tr>
                <c:forEach items="${actionBean.customers}" var="customer">
                    <tr>
                        <td><c:out value="${customer.id}"/></td>
                        <td><c:out value="${customer.firstName}"/></td>
                        <td><c:out value="${customer.lastName}"/></td>
                        <td><c:out value="${customer.city}"/></td>
                        <td><c:out value="${customer.street}"/></td>
                        <td><c:out value="${customer.streetNumber}"/></td>
                        <td><c:out value="${customer.postalCode}"/></td>
                        <td><c:out value="${customer.phoneNumber}"/></td>
                        <td><c:out value="${customer.email}"/></td>
                        <td><s:link class="btn btn-small" beanclass="cz.muni.fi.pa165.web.ManagerCustomerActionBean" event="edit" href="/editCustomer.jsp">
                                <s:param name="customer.id" value="${customer.id}"/>
                                <f:message key="Manager-Customer-list-edit"/>
                            </s:link>
                        </td>
                        <td><s:link class="btn btn-small btn-danger" beanclass="cz.muni.fi.pa165.web.ManagerCustomerActionBean" event="delete">
                                <s:param name="customer.id" value="${customer.id}"/>
                                <f:message key="Manager-Customer-list-delete"/>
                            </s:link>
                        </td>
                    </tr>
                </c:forEach>
            </table>
    </s:layout-component>
</s:layout-render>
